package com.zeratul.common.feign.inter;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.zeratul.common.satoken.utils.LoginHelper;
import feign.RequestInterceptor;
import feign.RequestTemplate;

public class SaTokenFeignReqInterceptor implements RequestInterceptor {

    /**
     * Called for every request. Add data using methods on the supplied {@link RequestTemplate}.
     *
     * @param template
     */
    @Override
    public void apply(RequestTemplate template) {
        //获取当前的用户Token
        String token = LoginHelper.getToken();
        if (ObjectUtil.isNotEmpty(token)) {
            template.header(StpUtil.getTokenName(), token);
        }
    }
}
